package banco;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Criptor {
	private static MessageDigest md = null;
	 static{
		 try {
			 md = MessageDigest.getInstance("MD5");
			
		} catch (NoSuchAlgorithmException e) {
			// TODO: handle exception
		}
	 }
	 
	 private static char[] hexCodes(byte[] texto){
		 
		 char[] hexOutPut = new char[texto.length * 2];
		 String hexString;
		 for (int i = 0; i < texto.length; i++) {
			hexString = "00"+Integer.toHexString(texto[i]);
			hexString.toUpperCase().getChars(hexString.length()-2,hexString.length(), hexOutPut,i*2);
			
		}
		 
		 return hexOutPut;
		 
	 }
	 
	 public static String criptorGraf(String passwd){
		 if (md!=null) {
			 return new String(hexCodes(md.digest(passwd.getBytes())));
			
		}
		 return null;
		 
		 
	 }
	 

}


/*
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Criptografia {

 

    public static String criptografar(String pwd) {

        if (md != null) {
            return new String(hexCodes(md.digest(pwd.getBytes())));
        }

        return null;

    }

}

*/